home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.cs.arizona.edu
/
ftp.cs.arizona.edu.tar
/
ftp.cs.arizona.edu
/
icon
/
newsgrp
/
group93b.txt
/
000086_icon-group-sender _Fri May 14 11:47:26 1993.msg
< prev
next >
Wrap
Internet Message Format
|
1993-06-16
|
2KB
Received: by cheltenham.cs.arizona.edu; Fri, 14 May 1993 10:04:50 MST
Date: Fri, 14 May 93 11:47:26 CDT
From: John David Stone <stone@HILBERT.math.grin.edu>
Message-Id: <9305141647.AA24170@HILBERT.MATH.GRIN.EDU>
To: sboisen@bbn.com
Cc: icon-group@cs.arizona.edu
In-Reply-To: Sean Boisen's message of Fri, 14 May 93 09:46:40 -0400 <9305141346.AA10725@sanborn.bbn.com>
Subject: string stripping
Status: R
Errors-To: icon-group-errors@cs.arizona.edu
Sean Boysen asks:
> ... i have a string and i want to strip out certain characters
> (internal ones, so trim won't do it) ... am i missing some more
> idiomatic way to express this? Note there's two parts that i perceive as
> clunky: the testing of whether c is in badchars (i suppose you could
> make badchars a string and use find instead), and the control structure
> with explicit generation and assignment to a new string.
Explicit assignment is not a stylistic defect, since Icon is _not_
going to do in-place updating of the original string even if you use the
same variable name. New storage is going to be allocated for the result of
the stripping no matter what. However, it would be nice to break off
long sequences of goodchars instead of inspecting them singly; the
predefined upto procedure is the winning way to do this.
String scanning can be used to avoid the other problem:
bare := ""
badchars := '-.'
full ? {
while bare ||:= tab(upto(badchars)) do
move (1)
bare ||:= tab(0)
}
Or in English: Scan through the value of full, up to the next position
occupied by a badchar. Break off the part you've just scanned over and
append it to the value of bare. Advance one position to get past the
badchar. Repeat until there are no more badchars in the subject. Then
scan to the end and append what you've just scanned over to the value of
bare.
------ John David Stone - Lecturer in Computer Science and Philosophy -----
-------------- Manager of the Mathematics Local-Area Network --------------
-------------- Grinnell College - Grinnell, Iowa 50112 - USA --------------
-------- stone@math.grin.edu - (515) 269-3181 - stone@grin1.bitnet --------